import { Component, OnInit } from '@angular/core';
import { NavController, ModalController } from '@ionic/angular';
import { CacheService } from '@services/cache.service';
import { InstallService } from '@services/data.service/index';
import { EmitService } from '@services/emit.service';


@Component({
    selector: 'install',
    templateUrl: 'install.html',
    styleUrls: ['install.scss']
})

export class InstallPage implements OnInit {
    dataList = [];
    projectName;
    projectId;
    // dataList = [
    //     { areaName: '1#配电房', metersNumber: '6', areaId: 1 }
    // ];

    constructor(public navCtrl: NavController,
        public modalCtrl: ModalController,
        private cache: CacheService,
        private installService: InstallService,
        public emitService: EmitService
    ) {
        this.projectId = this.cache.currentProject.projectId;
        this.projectName = this.cache.currentProject.projectName;
    }

    ngOnInit() {
        this.getRooms();
    }

    getRooms() {
        this.installService.getAreaList(this.projectId).subscribe(res => {
            this.dataList = res.data;
        });
    }

    toInstall(item, i) {
        if (item) {
            const data = {
                areaId: item.areaId,
                areaName: item.areaName
            }
            this.emitService.installState =  data;
            this.navCtrl.navigateForward(['tabs/my/InstrumentPage']);
        }
    }

}
